import React, {Component} from 'react';

import {List} from 'antd';

import {Input, Button} from 'antd';
import PdfPreview from "./PdfPreview";

import {URL} from "../../../src/constant/Constant";


export default class PublishedPaper extends Component {
    constructor(props) {
        super(props);
        this.state = {
            ArticleData: '',
            path: "",//pdf请求路径
            inputValue: ''

        }
    }

    componentDidMount = () => {
        fetch(URL.urlRoot + "/documentlist", {
            method: "Get",
            headers: {
                "Content-Type": "application/json",
                'Authorization': window.localStorage.authorization,
            }
        }).then((res) => {
            return res.json()
        }).then((res) => {
            this.setState({
                ArticleData: res,
            });
        })

    }

    onClick(path) {
        this.setState({
            path: path
        })
    }

    handleInputValue = (e) => {
        this.setState({
            inputValue: e.target.value
        })
    }
    // 查询方法
    handleBtn = () => {
        const inputValue = this.state.inputValue;
    }

    render() {

        return (

            <div>

                <h1 style={{textAlign: 'center', marginBottom: '20px'}}>发表论文</h1>
                <div>
                    <Input placeholder='请输入关键字' value={this.state.inputValue}
                           onChange={this.handleInputValue}
                           style={{width: '300px', marginRight: '10px', marginBottom: 20}}/>
                    <Button onClick={this.handleBtn} type='primary'>查询</Button>
                </div>

                <div style={{float: 'left', width: '75%'}}>
                    <PdfPreview
                        path={this.state.path}
                        style={{float: 'left'}}
                    />
                </div>

                <div style={{float: 'right', width: '25%'}}>
                    <div
                        id={'rightmenu'}
                        style={{
                            width: '100%'
                        }}>
                        {/*<h1 style={{textAlign: 'center', marginBottom: '20px'}}>发表论文</h1>*/}
                        <List
                            size="small"
                            bordered
                            dataSource={this.state.ArticleData}
                            pagination={{
                                pageSize: 5,
                            }}

                            renderItem={(item, key) => (<List.Item>
                                    <span
                                        style={{cursor: 'pointer'}} id='span' key={key}
                                        onClick={() => this.onClick(item.downloadPath)}
                                    >{"《" + item.title + "》"}</span>
                            </List.Item>)}
                        />

                    </div>
                </div>

            </div>
        )
    }
}